home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / nlb_3drt / 3drotate.asm next >
Assembly Source File  |  1995-04-10  |  9KB  |  271 lines

  1.  
  2. ;
  3. ; 3d Rotation, Coded by Ash [NLB]
  4. ; it's not TOO fast, but it's more understandable this way.
  5. ;
  6.  
  7. ideal                        ; ideal RULES
  8. p386n                        ; 80386+
  9. jumps                        ; jumps
  10.  
  11. segment code
  12. assume cs:code,ds:code
  13. org 100h
  14.  
  15. start:
  16.         cli                ; clear interrupts
  17.  
  18.                 mov     ax,13h                  ; 320*200*256 Bios
  19.                 int     10h
  20.                 push    0a000h                  ; Dest. VgaSeg.
  21.                 pop     es
  22.  
  23.                 mov     dx,3c8h                 ; dump palette
  24.                 lea     si,[palette]
  25.                 mov     cx,189*3
  26.                 xor     al,al
  27.                 out     dx,al
  28.                 inc     dx
  29.                 repz    outsb
  30.  
  31. mainloop:       inc     [xangle]                ; do the Angles
  32.                 and     [xangle],255
  33.                 inc     [yangle]
  34.                 and     [yangle],255
  35.                 inc     [zangle]
  36.                 and     [zangle],255
  37.  
  38.                 mov     bp,[xangle]             ; get sin & cos values (x)
  39.                 movsx   bx,[sincos+bp]
  40.                 mov     [xsin],bx
  41.                 add     bp,64
  42.                 and     bp,255
  43.                 movsx   bx,[sincos+bp]
  44.                 mov     [xcos],bx
  45.  
  46.                 mov     bp,[yangle]             ; get sin & cos values (y)
  47.                 movsx   bx,[sincos+bp]
  48.                 mov     [ysin],bx
  49.                 add     bp,64
  50.                 and     bp,255
  51.                 movsx   bx,[sincos+bp]
  52.                 mov     [ycos],bx
  53.  
  54.                 mov     bp,[zangle]             ; get sin & cos values (z)
  55.                 movsx   bx,[sincos+bp]
  56.                 mov     [zsin],bx
  57.                 add     bp,64
  58.                 and     bp,255
  59.                 movsx   bx,[sincos+bp]
  60.                 mov     [zcos],bx
  61.  
  62.                 xor     si,si
  63.                 mov     cx,allpoints
  64. alldots:        push    cx
  65.                 mov     bx,[xcos]               ; yt=y*cos(x)-z*sin(x)
  66.                 movsx   ax,[points+si+1]
  67.                 imul    bx
  68.                 xchg    ax,bp
  69.                 mov     bx,[xsin]
  70.                 movsx   ax,[points+si+2]
  71.                 imul    bx
  72.                 sub     bp,ax
  73.                 mov     [yt],bp
  74.  
  75.                 mov     bx,[xsin]               ; zt=y*sin(x)+z*cos(x)
  76.                 movsx   ax,[points+si+1]
  77.                 imul    bx
  78.                 xchg    ax,bp
  79.                 mov     bx,[xcos]
  80.                 movsx   ax,[points+si+2]
  81.                 imul    bx
  82.                 add     bp,ax
  83.                 mov     [zt],bp
  84.  
  85.                 mov     ax,[yt]                 ; yt=y & zt=z
  86.                 sar     ax,7
  87.                 mov     [y],ax
  88.                 mov     ax,[zt]
  89.                 sar     ax,7
  90.                 mov     [z],ax
  91.  
  92.                 mov     bx,[ycos]               ; xt=x*cos(y)-z*sin(y)
  93.                 movsx   ax,[points+si]
  94.                 imul    bx
  95.                 xchg    ax,bp
  96.                 mov     bx,[ysin]
  97.                 mov     ax,[z]
  98.                 imul    bx
  99.                 sub     bp,ax
  100.                 mov     [xt],bp
  101.  
  102.                 mov     bx,[ysin]               ; zt=x*sin(y)+z*cos(y)
  103.                 movsx   ax,[points+si]
  104.                 imul    bx
  105.                 xchg    ax,bp
  106.                 mov     bx,[ycos]
  107.                 mov     ax,[z]
  108.                 imul    bx
  109.                 add     bp,ax
  110.                 mov     [zt],bp
  111.  
  112.                 mov     ax,[xt]                 ; xt=x & zt=z
  113.                 sar     ax,7
  114.                 mov     [x],ax
  115.                 mov     ax,[zt]
  116.                 sar     ax,7
  117.                 mov     [z],ax
  118.  
  119.                 mov     bx,[zcos]               ; xt=x*cos(z)-y*sin(z)
  120.                 mov     ax,[x]
  121.                 imul    bx
  122.                 xchg    ax,bp
  123.                 mov     bx,[zsin]
  124.                 mov     ax,[y]
  125.                 imul    bx
  126.                 sub     bp,ax
  127.                 mov     [xt],bp
  128.  
  129.                 mov     bx,[zsin]               ; yt=x*sin(z)+y*cos(z)
  130.                 mov     ax,[x]
  131.                 imul    bx
  132.                 xchg    ax,bp
  133.                 mov     bx,[zcos]
  134.                 mov     ax,[y]
  135.                 imul    bx
  136.                 add     bp,ax
  137.                 mov     [yt],bp
  138.  
  139.                 mov     ax,[xt]                 ; xt=x & zt=z
  140.                 sar     ax,7
  141.                 mov     [x],ax
  142.                 mov     ax,[yt]
  143.                 sar     ax,7
  144.                 mov     [y],ax
  145.  
  146.                 mov     ax,200                  ; x*200\z+200 = x
  147.                 mov     bx,[x]
  148.                 imul    bx
  149.                 mov     bx,[z]
  150.                 add     bx,200
  151.                 idiv    bx
  152.                 add     ax,160
  153.                 xchg    ax,bp
  154.  
  155.                 mov     ax,200                  ; y*200\z+200 = y
  156.                 mov     bx,[y]
  157.                 imul    bx
  158.                 mov     bx,[z]
  159.                 add     bx,200
  160.                 idiv    bx
  161.                 add     ax,100
  162.  
  163.                 mov     bx,320                  ; (y*320)+x
  164.                 mul     bx
  165.                 add     ax,bp
  166.                 xchg    di,ax
  167.  
  168.                 mov     ax,[z]                  ; get color of point from z
  169.                 add     ax,74
  170.  
  171.                 mov     [byte ptr es:di],al     ; dump a dot
  172.                 mov     [deltable+si],di        ; save position for erase
  173.  
  174.                 add     si,3
  175.                 pop     cx
  176.                 loop    alldots
  177.  
  178.                 mov     dx,3dah                 ; vertical retrace
  179.                 in      al,dx
  180.                 test    al,8
  181.                 jne     $-3
  182.                 in      al,dx
  183.                 test    al,8
  184.                 je      $-3
  185.  
  186.                 xor     si,si            ; erase points
  187.                 mov     cx,allpoints
  188. erasethem:      push    cx
  189.                 mov     di,[deltable+si]
  190.                 mov     [byte ptr es:di],0
  191.                 add     si,3
  192.                 pop     cx
  193.                 loop    erasethem
  194.  
  195.                 in      al,60h                  ; scan keyboard
  196.                 cmp     al,1                    ; is escape pressed?
  197.                 jne     mainloop                ; if not, loop 3d
  198.  
  199.                 mov     ax,3                    ; 80*25*16 Bios
  200.                 int     10h
  201.                 mov     ax,4c00h                ; go back to dos
  202.                 int     21h
  203.  
  204.  
  205.         ;
  206.         ; Data Starts here..
  207.         ;
  208.  
  209.  
  210.   label sincos byte
  211.   db 0,3,6,9,12,16,19,22,25,28,31,34,37,40,43,46,49,51,54,57,60,63,65,68,71
  212.   db 73,76,78,81,83,85,88,90,92,94,96,98,100,102,104,106,107,109,111,112,113
  213.   db 115,116,117,118,120,121,122,122,123,124,125,125,126,126,126,127,127,127
  214.   db 127,127,127,127,126,126,126,125,125,124,123,122,122,121,120,118,117,116
  215.   db 115,113,112,111,109,107,106,104,102,100,98,96,94,92,90,88,85,83,81,78,76
  216.   db 73,71,68,65,63,60,57,54,51,49,46,43,40,37,34,31,28,25,22,19,16,12,9,6,3,0
  217.   db 253,250,247,244,240,237,234,231,228,225,222,219,216,213,210,207,205,202
  218.   db 199,196,193,191,188,185,183,180,178,175,173,171,168,166,164,162,160,158
  219.   db 156,154,152,150,149,147,145,144,143,141,140,139,138,136,135,134,134,133
  220.   db 132,131,131,130,130,130,129,129,129,129,129,129,129,130,130,130,131,131
  221.   db 132,133,134,134,135,136,138,139,140,141,143,144,145,147,149,150,152,154
  222.   db 156,158,160,162,164,166,168,171,173,175,178,180,183,185,188,191,193,196
  223.   db 199,202,205,207,210,213,216,219,222,225,228,231,234,237,240,244,247,250
  224.   db 253
  225.  
  226.   label         points byte                     ; the points
  227.                 c = -35                ; 4x*4y*4z (=64) points
  228.                 rept 4
  229.                 b = -35
  230.                 rept 4
  231.                 a = -35
  232.                 rept 4
  233.                 db a,b,c
  234.                 a = a + 20
  235.                 endm
  236.                 b = b + 20
  237.                 endm
  238.                 c = c + 20
  239.                 endm
  240.  
  241.   label         palette byte                    ; the palette
  242.                 db 0,0,0            ; 63*2 greentint
  243.                 d = 63
  244.                 rept 63
  245.                 db 0,d,0,0,d,0
  246.                 d = d - 1
  247.                 endm
  248.  
  249.   allpoints     equ 64                ; total points
  250.  
  251.   xangle        dw 0
  252.   yangle        dw 0
  253.   zangle        dw 0
  254.   xsin          dw ?
  255.   ysin          dw ?
  256.   zsin          dw ?
  257.   xcos          dw ?
  258.   ycos          dw ?
  259.   zcos          dw ?
  260.   xt            dw ?
  261.   yt            dw ?
  262.   zt            dw ?
  263.   x             dw ?
  264.   y             dw ?
  265.   z             dw ?
  266.   deltable      dw allpoints dup (?)
  267.  
  268. ends code
  269. end start
  270.  
  271.